package com.lhf.person.service.impl;

import com.lhf.person.dao.PersonDao2;
import com.lhf.person.entity.Person;
import com.lhf.person.service.PersonService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;

@Service
public class PersonServiceimpl2 implements PersonService2 {
    @Autowired
    private PersonDao2 dao;
    @Override
    public Page<Person> foundPerson(String name, int sex, int pageindex) {
        PageRequest page = PageRequest.of(pageindex, 2);
        return dao.findAll(new MyClass(), page);
    }
    private class MyClass implements Specification<Person>{

        @Override
        public Predicate toPredicate(Root<Person> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
            Path<String>var1=root.get("name");
            Path<Integer> var2 = root.get("sex");
            Predicate predicate = cb.and(cb.like(var1,"%name%"));

            return null;
        }
    }
}
